<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/10/13
 * Time: 9:24
 */
namespace  Android\Model;
use Think\Model;


class UserModel extends Model
{
    //获取用户好友数，粉丝数，关注数
  public function  userdetails(&$user_id ){
         $user=D('user');
         $array=$user->field('nickname,sign,head_img')->where('user_id='.$user_id)->find();
         $friends_num=$user->alias(us)->join('friends fr on us.user_id=fr.user_id')->where("us.user_id=".$user_id." and fr.type=2")->count();
         $fans_num= $user->alias(us)->join('follow fo on us.user_id=fo.focus_id')->where('focus_id='.$user_id." and fo.type=2")->count();
         $focus=$user->alias(us)->join('follow fo on us.user_id=fo.focus_id')->where('us.user_id='.$user_id)->count();
         $array['friends_num']=$friends_num;
          $array['fans_num']=$fans_num;
          $array['focus_num']=$focus;
         return $array;

  }
  //得到粉丝的详细信息
  public  function  fanslist(&$user_id){
         $follow=D('follow');
         $fans['fans']= $follow->alias(fo)->join('user us on us.user_id=fo.user_id')->field('nickname,sign,head_img')->where('focus_id='.$user_id." and fo.type=2")->select();
        return $fans;
    }
    //获取朋友的列表
   public function friendlist(&$user_id){
       $info['friendlist']= $this->join('friends fr on user.user_id=fr.friend_id')->field('nickname,sign,head_img')->where('fr.type=2 and fr.user_id='.$user_id)->select();
       return $info;
   }
   //我的信息编辑
    public function  myinfoedit(){

    }
    //获取个人信息
    public function myinfo(&$user_id){
       $info=  $this->field('user_id,nickname,sex,birth,city,phone')->where('user_id='.$user_id)->select();
        return $info;
    }
    //个人信息修改
    public function myinfoChange($user_id){
        $data=$this->create();
        $info=$this->where('user_id='.$user_id)->save($data);
        return $info;
    }
 //

}